<template>
  <el-dialog :title="!dataForm.id ? '详情' : '详情'" :close-on-click-modal="false" :visible.sync="visible">

    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
      <el-form-item label="商家" prop="sellerId">
        <span>{{dataForm.sellerName}}</span>
      </el-form-item>
      <el-form-item label="操作员" prop="userId">
        <span>{{dataForm.userName}}</span>
      </el-form-item>
      <el-form-item label="时间" prop="parameter">
        <span>{{dataForm.creatTime}}</span>
      </el-form-item>
      <!-- 商户信息-->
      <div v-if="dataForm.type == 0">

      </div>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="successHandle(dataForm.id)" v-if="dataForm.state == 0">通过</el-button>
      <el-button type="danger" @click="rejectHandle(dataForm.id)" v-if="dataForm.state == 0">驳回</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        visible: false,
        dataForm: {
          id: 0,
          sellerId: '',
          userId: '',
          parameter: '',
          state: '',
          type: '',
          entityBean: '',
          springBean: '',
          creatTime: '',
          updateTime: '',
          operator: ''
        },
        dataRule: {
          sellerId: [{
            required: true,
            message: '商家不能为空',
            trigger: 'blur'
          }],
          userId: [{
            required: true,
            message: '用户ID不能为空',
            trigger: 'blur'
          }],
          parameter: [{
            required: true,
            message: '参数不能为空',
            trigger: 'blur'
          }],
          state: [{
            required: true,
            message: '状态(0待审1通过2驳回)不能为空',
            trigger: 'blur'
          }],
          type: [{
            required: true,
            message: '类型(0商家信息1商家实名信息2商家信息图片3商家房型图片)不能为空',
            trigger: 'blur'
          }],
          entityBean: [{
            required: true,
            message: '实体类不能为空',
            trigger: 'blur'
          }],
          springBean: [{
            required: true,
            message: '反射service不能为空',
            trigger: 'blur'
          }],
          creatTime: [{
            required: true,
            message: '创建时间不能为空',
            trigger: 'blur'
          }],
          updateTime: [{
            required: true,
            message: '更新时间不能为空',
            trigger: 'blur'
          }],
          operator: [{
            required: true,
            message: '操作员不能为空',
            trigger: 'blur'
          }]
        }
      }
    },
    methods: {

      successHandle(id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '通过' : '批量通过'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/seller/tsellerhistoricaldata/seller/success'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({
            data
          }) => {
            if (data && data.code === 0) {
              this.visible = false
              this.$emit('refreshDataList')
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      rejectHandle(id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '驳回' : '批量驳回'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.rejectTwo(ids);
        })
      },
      rejectTwo(ids) {
        this.$prompt('请输入理由', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
          inputErrorMessage: '理由不能为空'
        }).then(({
          value
        }) => {
          this.$http({
            url: this.$http.adornUrl('/seller/tsellerhistoricaldata/seller/reject'),
            method: 'post',
            params: this.$http.adornParams({
              'ids': ids.join(","),
              'reason': value,
            })
          }).then(({
            data
          }) => {
            if (data && data.code === 0) {
              this.visible = false
              this.$emit('refreshDataList')
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        }).catch(() => {

        });
      },
      init(id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/seller/tsellerhistoricaldata/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                this.dataForm.sellerName = data.data.tSellerHistoricalData.sellerName
                this.dataForm.userName = data.data.tSellerHistoricalData.userName
                this.dataForm.operatorName = data.data.tSellerHistoricalData.operatorName
                this.dataForm.creatTime = data.data.tSellerHistoricalData.creatTime
                this.dataForm.updateTime = data.data.tSellerHistoricalData.updateTime
                this.dataForm.gsonEntity = data.data.tSellerHistoricalData.gsonEntity
                this.dataForm.type = data.data.tSellerHistoricalData.type
                this.dataForm.state = data.data.tSellerHistoricalData.state
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/seller/tsellerhistoricaldata/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'sellerId': this.dataForm.sellerId,
                'userId': this.dataForm.userId,
                'parameter': this.dataForm.parameter,
                'state': this.dataForm.state,
                'type': this.dataForm.type,
                'entityBean': this.dataForm.entityBean,
                'springBean': this.dataForm.springBean,
                'creatTime': this.dataForm.creatTime,
                'updateTime': this.dataForm.updateTime,
                'operator': this.dataForm.operator
              })
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
